#ifndef __VIDEO_MANAGER_H__
#define __VIDEO_MANAGER_H__

#include "common.h"
#include <linux/videodev2.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

#define MEDIA_LOG_INFO(format, ...) hlogi(format, ##__VA_ARGS__)
#define MEDIA_LOG_WARN(format, ...) hlogw(format, ##__VA_ARGS__)
#define MEDIA_LOG_ERROR(format, ...) hloge(format, ##__VA_ARGS__)
#define MEDIA_LOG_DEBUG(format, ...) hlogd(format, ##__VA_ARGS__)

typedef struct video_devices {
    int fd;
    int width;
    int height;
    int pixelformat;
    uint32_t buf_size;
    int num_planes;
    int index;

    image_buffer_t mmap_buf[BUF_COUNT];
    struct v4l2_buffer buffer;

    volatile int thread_run;
    pthread_t thread;
    struct video_opr *video_opr;
} video_dev_t;

typedef struct video_opr {
    char *name;
    video_dev_t *video;
    int (*dev_init)(video_dev_t *video_dev);
    int (*dev_exit)(video_dev_t *video_dev);
    int (*query_cap)(video_dev_t *video_dev);
    int (*enum_formats)(video_dev_t *video_dev);
    int (*set_format)(video_dev_t *video_dev);
    int (*get_format)(video_dev_t *video_dev);
    int (*get_frame)(video_dev_t *video_dev);
    int (*put_frame)(video_dev_t *video_dev);
    int (*dev_start)(video_dev_t *video_dev);
    int (*dev_stop)(video_dev_t *video_dev);
    struct video_opr *next;
} video_opr_t;

int register_video(video_opr_t *video_opr);
image_format_t get_img_format(int fmt);
video_opr_t *get_video(const char *pcName);
int all_video_init(void);
int all_video_start(void);

void mipi_cam_register(video_dev_t *video);
void usb_cam_register(video_dev_t *video);

#ifdef __cplusplus
}    // extern "C"
#endif

#endif    // __VIDEO_MANAGER_H__